package com.chima.service.impl;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

import com.chima.dao.DetailPostDao;
import com.chima.domain.Advice;
import com.chima.domain.DetailPost;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.service.DetailPostService;
public class DetailPostServiceImp implements DetailPostService {
	private DetailPostDao detailPostDao;
	

	public DetailPostDao getDetailPostDao() {
		return detailPostDao;
	}

	public void setDetailPostDao(DetailPostDao detailPostDao) {
		this.detailPostDao = detailPostDao;
	}

	public PageResponseBean findDetailPost(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = detailPostDao.findByTotalCount(pageRequestBean.getEmp());
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(DetailPost.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<DetailPost> DetailPosts= detailPostDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(DetailPosts);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveDetailPost(DetailPost detailPost) {
		detailPostDao.save(detailPost);
		
	}

	public void updateDetailPost(DetailPost detailPost) {
		detailPostDao.update(detailPost);
		
	}

	public void deleteDetailPost(int id) {
		detailPostDao.delete(id);
		
	}

	public List<DetailPost>findByPostAndEmp(int post, int emp) {
		return detailPostDao.findByPostAndEmp(post, emp);
	}

	public DetailPost findByNameAndEmp(String name, int emp) {
		
		return detailPostDao.findByNameAndEmp(name, emp);
	}

	public List<DetailPost> findByDeptId(int DeptId) {
		
		return detailPostDao.findByDeptId(DeptId);
	}

	public void deleteDetailPostByEmp(int empid) {
		
		detailPostDao.deleteDetailPostByEmp(empid);
		
	}

}
